package com.aptemo.webetek.server.handlers;

import com.aptemo.webetek.client.commands.Action;
import com.aptemo.webetek.client.commands.impl.ModifyBeanAction;
import com.aptemo.webetek.client.exceptions.BackendException;
import com.aptemo.webetek.client.exceptions.WebetekLoginException;
import com.aptemo.webetek.client.exceptions.BackendException.EErrorCodes;
import com.aptemo.webetek.server.datastore.DataStoreAPI;
import com.aptemo.webetek.shared.LabelBean;

public class ModifyLabelHandler
		extends ActionHandler<ModifyBeanAction, LabelBean>
{

	public ModifyLabelHandler(DataStoreAPI dataService)
	{
		super(dataService);
	}

	public Class<? extends Action<?>> getActionType()
	{
		return ModifyBeanAction.class;
	}

	@Override
	public LabelBean invoke(ModifyBeanAction action) throws BackendException, WebetekLoginException
	{
		utils.checkLogin();

		if (!utils.isTeamEditor(action.getBean().getTeamId()))
		{
			throw new BackendException(EErrorCodes.NOT_TEAM_EDITOR);
		}
		return dataService.modifyLabel(action.getBean());
	}
}
